package com.biz.primus.management.order.controller;

import com.biz.primus.base.vo.PageResult;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.management.order.feign.OmsFeignClient;
import com.biz.primus.model.oms.vo.OrderQueryVo;
import com.biz.primus.model.oms.vo.OrderReturnQueryVo;
import com.biz.primus.model.oms.vo.returns.OmsReturnVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

/**
 * @note: 退货单列表控制层
 * @author: wj
 * @careat: 2017-11-22 10:34
 **/
@Controller
@RequestMapping("salesReturnListController")
public class SalesReturnListController {

    @Autowired
    private OmsFeignClient omsFeignClient;

    /**
     * 退货单列表首页(首页,跳转)
     *
     * @return
     */
    @GetMapping
    public ModelAndView salesReturnListMain() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("salesReturnList/list");
        return modelAndView;
    }

    /**
     * 跳转到申请退货页面
     *
     * @return
     */
    @GetMapping("applySalesReturn")
    public ModelAndView applySalesReturn() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("salesReturnList/details");
        return modelAndView;
    }

    /**
     * 跳转到商品信息页面
     *
     * @return
     */
    @GetMapping("merchandiseNews")
    public ModelAndView merchandiseNews() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("salesReturnList/merchandiseNews");
        return modelAndView;
    }

    /**
     * 后台退单列表查询
     *
     * @return
     */
    @GetMapping("managementReturnQueryList")
    @ResponseBody
    public Map<String, Object> managementReturnQuery(String orderCode, int start, int length) {//star和length这两个参数是分页参数
//        OrderQueryVo orderQueryVo = new OrderQueryVo();
        OrderReturnQueryVo orderReturnQueryVo = new OrderReturnQueryVo();
        // 添加分页数据
        orderReturnQueryVo.setPage(start + 1);
        orderReturnQueryVo.setSize(length);
        orderReturnQueryVo.setOrderCode(orderCode);
        //存查询出来的数据
        Map<String, Object> result = new HashMap<>();
        //请求查询对象

        PageResult<OmsReturnVo> omsReturnVoPageResult = omsFeignClient.managementReturnQuery(orderReturnQueryVo);

//        SpringPageVO<OmsReturnVo> returnQuery = omsFeignClient.managementReturnQuery(orderReturnQueryVo);
        result.put("iTotalRecords", omsReturnVoPageResult.getContent().size());//数据总条数
        result.put("iTotalDisplayRecords", omsReturnVoPageResult.getContent().size());//显示的条数
        result.put("aaData", omsReturnVoPageResult.getContent());//返回数据
        return result;
    }
}
